﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TMT.Data.Base;
using TMT.Data;
using TMT.Data.Common;

namespace TMT.Admin
{
    public partial class Site : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["TMTAccount"] == null && Request.Cookies["TMTAccount"] == null)
            {
                Response.Redirect("~/Login.aspx");
            }
            else if (Request.Cookies["TMTAccount"] != null && Session["TMTAccount"] == null)
            {
                AccountMaster account = new AccountMaster()
                {
                    UserId = Request.Cookies["TMTAccount"]["UserId"] == null ? string.Empty : Request.Cookies["TMTAccount"]["UserId"],
                    Password = Request.Cookies["TMTAccount"]["Password"] == null ? string.Empty : Request.Cookies["TMTAccount"]["Password"]
                };
                OperationResult loginResult = AccountService.Instance.Login(account);
                if (!loginResult.Result)
                {
                    Response.Redirect("~/Login.aspx");
                }
                else
                {
                    Session["TMTAccount"] = loginResult.ReturnObject;
                }
            }

        }
    }
}